package com.focusai.efairy.model.request;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.project.UpLoadProjectEntity;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.PutPureJSONRequest;
import com.focusai.efairy.network.utils.UrlUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Map;

/**
 * Created by luo_guangwen on 2017/8/13.
 */

public class PuteditProjectRequest extends PutPureJSONRequest<String> {
    private UpLoadProjectEntity projectEntity;

    public PuteditProjectRequest(UpLoadProjectEntity projectEntity, Response.Listener<String> listener) {
        super(UrlUtils.createUrl("/appapi/project"), listener);
        this.projectEntity = projectEntity;
    }

    @Override
    protected String parse(String result) throws ParseException {
//        return GsonHelper.getInstance().fromJson(result, new TypeToken<ResultInfo<String>>() {
//        }.getType());
        return result;
    }

    @Override
    public Map<String, String> getParams() throws JSONException {
        return super.getParams();
    }

    @Override
    public String getPureJSON() throws JSONException {
        if (projectEntity != null){
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("efairyuser_id", CacheManager.getUserId());
            jsonObject.put("access_token", CacheManager.getAccessToken());
            jsonObject.put("efairyproject_name", projectEntity.efairyproject_name);
            jsonObject.put("efairyproject_id", projectEntity.efairyproject_id);
            jsonObject.put("efairyproject_fee_type", 1);
            jsonObject.put("efairyproject_user_name", projectEntity.efairyproject_user_name);
            jsonObject.put("efairyproject_user_phonenumber", projectEntity.efairyproject_user_phonenumber);
            jsonObject.put("efairyproject_description", projectEntity.efairyproject_description == null ? "":projectEntity.efairyproject_description);
            jsonObject.put("efairyproject_address", projectEntity.efairyproject_address);
            jsonObject.put("efairyproject_location_lng", projectEntity.efairyproject_location_lng);
            jsonObject.put("efairyproject_location_lat", projectEntity.efairyproject_location_lat);
            return jsonObject.toString();
        }
        return null;
    }

}
